package com.f.manage.线程;

import cn.hutool.core.math.MathUtil;
import com.f.manage.面向对象.superr.Person;

import java.security.SecureRandom;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ExecutionException;

public class CompletableFutureTest {

    public static void main(String[] args) {

            System.out.println(11);
            CompletableFuture<Integer> c1 = CompletableFuture.supplyAsync(()->{
                SecureRandom random = new SecureRandom();
                int i = random.nextInt(100);
                return i;
            }).exceptionally(e->{
                System.out.println("yichang");
                return 10;
            }).thenApply(e->{
                System.out.println("上一步的执行的结果为：" + e);
                return e+100;
            });
        System.out.println(777);
        CompletableFuture<Integer> c2 = CompletableFuture.supplyAsync(()->{
            SecureRandom random = new SecureRandom();
            for(int i=0;i<1000000;i++){
                System.out.println(i);
            }
            int i = random.nextInt(100);
            return i;
        });
        System.out.println(666);
        CompletableFuture f = c1.thenCombine(c2, (flushStatus, replicaStatus) -> {
            boolean flag = false;
            try {
                System.out.println(c1.get());
                System.out.println(c2.get());
                if(c1.get().intValue() >50 && c2.get().intValue() >50){
                    flag = true;
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
            return flag;

        });

        System.out.println(f.join());
        System.out.println(11111);


    }

}
